package com.lhf.person.dao;

import com.lhf.person.entity.Person;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.io.Serializable;

public interface PersonDao extends JpaRepository<Person, Serializable> {
    @Query(value = "select * from person where name like?1 and sex=?2 /*pageable*/",
    countQuery = "select count(id) from person where name like?1 and sex=?2",nativeQuery = true)
    Page<Person> findByNameAndSex(@Param("name") String name, @Param("sex") int sex, Pageable pageable);//通过名字和性别查找
    @Query(value = "select * from person where name like?1 /*pageable*/",
            countQuery = "select count(id) from person where name like?1",nativeQuery = true)
    Page<Person>findByName(String name,Pageable pageable);//通过名字查找
    @Query(value = "select * from person where sex=?1 /*pageable*/",
            countQuery = "select count(id) from person where sex=?1",nativeQuery = true)
    Page<Person>findBySex(int sex,Pageable pageable);//通过性别查找
    @Query(value = "select introduce from person where id=?1", nativeQuery = true)
    String findintroduce(int id);//查单个信息
}
